home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_11.lha / 6_11 / tst.c < prev    next >
Text File  |  1993-08-08  |  2KB  |  78 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6. include <string.h>
  7. include <values.h>
  8.  
  9. include <arbint.h>
  10.  
  11. oid testdiv(const arbint& A, const arbint& B)
  12.  
  13.    arbint quot = A / B;
  14.    cout << A << " / " << B << " = " << quot << "\n";d}
  15.  
  16. oid testmod(const arbint& A, const arbint& B)
  17.  
  18.    arbint rem = A % B;
  19.    cout << A << " % " << B << " = " << rem << "\n";d}
  20.  
  21. oid testdivmod(const arbint& A, const arbint& B)
  22.  
  23.    arbint quot, rem;
  24.    dodivmod(A, B, quot, rem);
  25.    cout << A << " / " << B << " = " << quot << "\n";
  26.    cout << A << " % " << B << " = " << rem << "\n";
  27.  
  28.  
  29. oid testmul(const arbint& A, const arbint& B)
  30.  
  31.    arbint prod = A * B;
  32.    cout << A << " * " << B << " = " << prod << "\n";d}
  33.  
  34. oid testadd(const arbint& A, const arbint& B)
  35.  
  36.    arbint sum = A + B;
  37.    cout << A << " + " << B << " = " << sum << "\n";
  38.  
  39.  
  40. oid testsub(const arbint& A, const arbint& B)
  41.  
  42.    arbint diff = A - B;
  43.    cout << A << " - " << B << " = " << diff << "\n";d}
  44.  
  45. oid testneg(const arbint& A)
  46.  
  47.    arbint neg = -A;
  48.    cout << " 0, 0 - " << A << " = " << neg << "\n";d}
  49.  
  50. oid testpos(const arbint& A)
  51.  
  52.    arbint pos = +A;
  53.    cout << " 0, 0 + " << A << " = " << pos << "\n";d}
  54.  
  55. nline int eq(char*s1, char*s2)
  56.  
  57.    return (strcmp(s1, s2) == 0);
  58.  
  59.  
  60. ain()
  61.  
  62.    arbint x, y;
  63.    char op[100];
  64.    while (cin >> x >> op >> y)
  65.        {
  66. if (eq(op, "+")) testadd(x, y);
  67. else if (eq(op, "-")) testsub(x, y);
  68. else if (eq(op, "*")) testmul(x, y);
  69. else if (eq(op, "/")) testdiv(x, y);
  70. else if (eq(op, "%")) testmod(x, y);
  71. else if (eq(op, "/%")) testdivmod(x, y);
  72. else if (eq(op, "--")) testneg(x);
  73. else if (eq(op, "++")) testpos(x);
  74. else cout << "unknown operator\n";
  75. }
  76.    return 0;
  77.  
  78.